﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace FBA.Client.Converters
{
    /// <summary>
    /// 字符串处理转换器
    /// </summary>
    public partial class StringReplaceCutConverter : IValueConverter
    {
        
        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && value != DBNull.Value)
            {
                string str = value.ToString().Replace("\r\n", "").Replace("\n", "").Replace("\t", "");
                if (parameter != null)
                {
                    int length = 0;
                    int.TryParse(parameter.ToString(),out length);
                    if(length > 0 && str.Length > length)
                    {
                        str = str.Substring(0, length) + "...";
                    }
                }
                return str;
            }
            return null;
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new Exception();
        }
    }
}
